package Ep01_Array.Feb26th_0680;



/**
 * @author Jimmy Zhan WORKSTATION
 * @Date 2023/2/28 8:32
 * 说明：680 验证回文串，典型双指针 low、high
 */

public class Mine {
    boolean del = false;
    public static void main(String[] args) {
        Mine m = new Mine();
        String s = "abca";
        System.out.println(m.validPalindrome(s));
    }

    public boolean validPalindrome(String s) {
        int low = 0;
        int high = s.length()-1;
        while(low < high){
            if (s.charAt(low) == s.charAt(high)){
                low ++;
                high --;
            } else {
                if (del == true){
                    return false;
                } else {
                    del = true;
                    // substring(int beginIndex, int endIndex)方法两个参数，表示的区间左闭右开
                    return validPalindrome(s.substring(low, high)) || validPalindrome(s.substring(low+1, high+1));
                }

            }
        }
        return true;

    }

}
